<?
class SubPollBO extends BusinessObject{

  /* private function using in constructors */ 
  function setAttributes(){
	$this->fields	= array(
		'id'			=>	'sub_poll_ID',
		'poll_id'		=>	'sub_poll_PollID',
		'name'		=>	'sub_poll_Name',
		'descr'		=>	'sub_poll_Descr',
		'visible'		=>	'sub_poll_Visible',
		'article_id'	=>	'sub_poll_ArticleID'
		);

    $t = new PollBO();
    $this->relations = array("{$t->tableName}" =>"{$t->tableName}.{$t->fields[id]} = {$this->tableName}.{$this->fields[poll_id]}");

    BusinessObject::setAttributes();
  }
  /* constructor */
  function SubPollBO(){
    /** super(tableName) */
    BusinessObject::BusinessObject("sub_poll");
    $this->setAttributes();
  }
  
    /*  Save  */
  function Save($pollID, $sub_pollID){
    if(is_numeric($pollID) && $pollID<>0){
      $this->id = $pollID;
      $this->poll_id = $sub_pollID;
      $this->Update("{$this->fields[id]} = '$pollID'");  
    } else{
      $this->Insert();
      $this->id = $this->getInsertID();
    }
  }

  // function 'get_subpoll_as_html' return the tag(s) OPTION with names and ids
  function get_subpoll_as_html($selected_subpollID, $poll_id){
    $reg = new SubPollBO();
	$reg->poll_id = $poll_id;
    $ret = "";
    $reg->Load(0,0,array($reg->fields['name']=>0));
    while ($reg->Next()) {
      $ret.= "<option value='{$reg->id}' ".(($selected_subpollID==$reg->id)?"selected":"").">".htmlspecialchars($reg->name)."</option>";
    }
    return $ret;
  }

}
?>